<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
/* $arr 要遍历的数组
 * 顶级分类的pid
 *  分类级别
 */
//公共无极限分类函数
function GetTree($arr, $pid=0, $step=0)
{
    global $tree;
    foreach ($arr as $key => $val) {
        if ($val['pid'] == $pid) {
            $flg = str_repeat('|—', $step);
            $val['name'] = $flg . $val['name'];
            $tree[] = $val;
            GetTree($arr, $val['id'], $step + 1);
        }
    }
    return $tree;
}
//格式化layUI的json数据格式
/*{
    "code": 0,
  "msg": "",
  "count": 1000,
  "data": [{}, {}]
}*/
function layJson($data,$msg='请求成功',$code=0){
    return json([
        'code'=>$code,
        'msg'=>$msg,
        'count'=>1000,
        'data'=>$data
    ]);
}